﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MINERP.DAL.GenerateReports
{
    public class ProductStatisticsDAL:DALBase
    {
        #region 获取一个产品的总面积
        /// <summary>
        /// 获取一个产品的总面积
        /// </summary>
        /// <param name="orderInfoCode"></param>
        /// <returns></returns>
        public static double GetAreaOfAOrderInfo(string orderInfoCode)
        {
            try
            {
                List<photoInfo> ListPhoto = DataEntites.photoInfo.Where(p => p.orderInfo.OrderProductCode == orderInfoCode).ToList();
                double area = 0;
                foreach (photoInfo photo in ListPhoto)
                {
                    double h = photo.Height * 2.54 / 100;
                    double w = photo.Width * 2.54 / 100;
                    area += h * w;                          //结果按平方米统计
                }
                return area;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region 获取一段时间内所有的BillDetail
        /// <summary>
        /// 获取一段时间内所有的BillDetail
        /// </summary>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <returns></returns>
        public List<Bill_Detail> GetListBillDetail(DateTime startTime, DateTime endTime)
        {
            try
            {
                List<Bill_Detail> listBillDetail = DataEntites.Bill_Detail.Where(p => p.SHOP_Bill.CreateTime > startTime && p.SHOP_Bill.CreateTime < endTime).ToList<Bill_Detail>();
                return listBillDetail;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region 获取具体某个产品的金额
        /// <summary>
        /// 获取具体某个产品的金额
        /// </summary>
        /// <param name="billDetailId"></param>
        /// <returns></returns>
        public double GetPriceOfAOrderInfo(int billDetailId)
        {
            try
            {
                List<Bill_Detail_Detail> ListDetail = DataEntites.Bill_Detail_Detail.Where(p => p.Bill_Detail.BillDetailId == billDetailId).ToList<Bill_Detail_Detail>();
                double m = 0;
                foreach (Bill_Detail_Detail bdd in ListDetail)
                {
                    m += bdd.Count;
                }
                return m;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region 根据产品编号获取其产品模板
        /// <summary>
        /// 根据产品编号获取其产品模板
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public Tb_Product GetProductByOrderInfoCode(string code)
        {
            try
            {
                orderInfo info = DataEntites.orderInfo.Where(p => p.OrderProductCode == code).FirstOrDefault();
                if (info == null)
                    return null;
                //Tb_Product product = DataEntites.Tb_Product.Where(p => p.orderInfo.Contains (info)).First();
                if (!info.Tb_ProductReference.IsLoaded)
                    info.Tb_ProductReference.Load();
                return info.Tb_Product;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion
    }
}
